package com.gxa.system_setting.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gxa.common.R;
import com.gxa.common.entity.system_settings.PlatformDistribution;
import com.gxa.system_setting.mapper.PlatformDistributionMapper;
import com.gxa.system_setting.service.PlatformDistributionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PlatformDistributionServiceImpl implements PlatformDistributionService {

    @Autowired
    private PlatformDistributionMapper platformDistributionMapper;

    @Override
    public R queryPlatformDistributionList(Integer currentPage, Integer pageSize) {
        R r=new R();
        Page page=new Page(currentPage,pageSize);
        Page platformDistributionList = platformDistributionMapper.selectPage(page, null);
        r.setCode(200);
        r.setMessage("查询成功");
        r.setData(platformDistributionList);
        return r;
    }

    @Override
    public R updatePlatformDistribution(PlatformDistribution platformDistribution) {
        R r=new R();
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.eq("platform_distribution_id",platformDistribution.getPlatformDistributionId());
        platformDistributionMapper.update(platformDistribution,queryWrapper);
        r.setCode(200);
        r.setMessage("修改成功");
        return r;
    }

    @Override
    public R stopOrUse(Long platform_distribution_id,Integer isFlag) {
        R r=new R();
        int i= platformDistributionMapper.stopOrUse(platform_distribution_id,isFlag);
        r.setCode(200);
        r.setMessage("改变成功");
        return r;
    }

    @Override
    public R queryByScopeApplicationOrStatus(String scopeApplication, Integer status) {
        R r=new R();
        QueryWrapper<PlatformDistribution> queryWrapper = new QueryWrapper<>();
        queryWrapper .and((wrapper) -> {
            wrapper.eq("status", status).or().like("scope_application", scopeApplication);
        });
        List<PlatformDistribution> list = platformDistributionMapper.selectList(queryWrapper);
        r.setCode(200);
        r.setMessage("查询成功");
        r.setData(list);
        return r;
    }

    @Override
    public R insertPlatformDistribution(PlatformDistribution platformDistribution) {
        R r=new R();
        int insert = platformDistributionMapper.insert(platformDistribution);
        r.setCode(200);
        r.setMessage("添加成功");
        return r;
    }
}
